//
//  FDDocterInfoController.m
//  FamousDoctorOnline
//
//  Created by 张睿 on 16/7/8.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDDocterInfoController.h"
#import <Masonry.h>
#import "FDTableVIewVC.h"
#import "FDtotalView.h"
#import "FDMDataModel.h"
#import <UIImageView+WebCache.h>

@interface FDDocterInfoController ()<UIScrollViewDelegate>

@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)UIView * scrollerView;
@property (nonatomic, strong)UIButton * bottomBtn;
@property (nonatomic, strong)UICollectionView * colView;
@property (nonatomic, weak)UILabel * nameTitle;

@property (nonatomic, strong)FDtotalView * tatalView;



@end

@implementation FDDocterInfoController


- (void)setDataModel:(FDMDataModel *)dataModel{
    _dataModel = dataModel;
    
}


- (void)viewDidLoad{
    
    [super viewDidLoad];
    //    //布局灰线上一部分
    [self setupTopView];
    //    //布局Nav
    [self setupNavController];
    //    //两个button按钮,及View
    [self setupButton];
    //最下面的一个button
    [self setupBottomView];
   
   self.tatalView = [[FDtotalView alloc] init];
    
    [self.view addSubview:self.tatalView];
    
    [self.tatalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.top.mas_equalTo(self.scrollerView.mas_bottom).offset(2);
        make.bottom.mas_equalTo(self.bottomBtn.mas_top).offset(-3);
    }];
    
    [self.tatalView sentText:^(int conoffset) {
//        if ((conoffset = self.view.bounds.size.width)) {
            if (conoffset) {
                
                [UIView animateWithDuration:0.5 animations:^{
                    self.conditionButton.selected = NO;
                    self.doctorInfoButton.selected = YES;
                    self.scrollerView.transform = CGAffineTransformMakeTranslation(SCREEN_WIDTH - 200, 0);
                }];
            }else{
                
                [UIView animateWithDuration:0.5 animations:^{
                    self.doctorInfoButton.selected = NO;
                    self.conditionButton.selected = YES;
                    self.scrollerView.transform = CGAffineTransformMakeTranslation(0, 0);
                }];
                return;
            }
//        }
    }];

    
}


- (void)buttonIsSelect{
    
    if (self.conditionButton.isSelected) {
        
        [UIView animateWithDuration:0.5 animations:^{
            self.scrollerView.transform = CGAffineTransformMakeTranslation(0, 0);
        }];
    }
   
    if (self.doctorInfoButton.isSelected) {
        [UIView animateWithDuration:0.5 animations:^{
            self.scrollerView.transform = CGAffineTransformMakeTranslation(SCREEN_WIDTH - 200, 0);
        }];
    }
    
}


- (void)setupButton{
    //中线
    UIView * verticalView = [UIView new];
    verticalView.backgroundColor = [UIColor colorWithRed:230 / 255.0 green:231 / 255.0 blue:233 / 255.0 alpha:1];
    [self.view addSubview:verticalView];
    
    [verticalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(5);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(2);
        make.height.mas_equalTo(35);
    }];
    //就诊Button
    self.conditionButton = [UIButton new];
    [self.conditionButton setTitle:@"就诊条件" forState:UIControlStateNormal];
    self.conditionButton.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.conditionButton setTitleColor:[UIColor colorWithRed:230 / 255.0 green:231 / 255.0 blue:233 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.conditionButton setTitleColor:[UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1] forState:UIControlStateSelected];
    [self.view addSubview:self.conditionButton];
    
    [self.conditionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(8);
        make.leading.offset(60);
    }];
    
    [self.conditionButton addTarget:self action:@selector(didCondictionClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.conditionButton.selected = YES;
    //医生简介
    self.doctorInfoButton = [UIButton new];
    [self.doctorInfoButton setTitle:@"医生信息" forState:UIControlStateNormal];
    self.doctorInfoButton.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.doctorInfoButton setTitleColor:[UIColor colorWithRed:230 / 255.0 green:231 / 255.0 blue:233 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.doctorInfoButton setTitleColor:[UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1] forState:UIControlStateSelected];
    [self.view addSubview:self.doctorInfoButton];
    
    [self.doctorInfoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(8);
        make.trailing.offset(-60);
    }];
    [self.doctorInfoButton addTarget:self action:@selector(didDoctorInfoClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //就诊Button下面的
    
    self.scrollerView = [[UIView alloc] init];

    self.scrollerView.backgroundColor = [UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1];
    [self.view addSubview:self.scrollerView];
    
    [self.scrollerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.conditionButton.mas_bottom).offset(10);
        make.leading.offset(50);
        make.height.mas_equalTo(3);
        make.width.mas_equalTo(100);
        
    }];
}

- (void)setupNavController{
    
    self.navigationItem.title = @"医生基本信息";
    
    UIBarButtonItem * buttonItem = [[UIBarButtonItem alloc] init];
    [buttonItem setImage:[UIImage imageNamed:@"kongxin"]];
    self.navigationItem.rightBarButtonItem = buttonItem;
}

- (void)setupTopView{
    //头像图片
    UIImageView * iconImage = [[UIImageView alloc] init];
    iconImage.layer.cornerRadius = 40;
    iconImage.clipsToBounds = YES;
    NSURL *url = [NSURL URLWithString:_dataModel.doctor_portrait];
    
    UIImage *image = [UIImage imageNamed:@"illness_img_person.png"];
    
    [iconImage sd_setImageWithURL:url placeholderImage:image completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        iconImage.image = image;
    }];
    
    [self.view addSubview:iconImage];
    
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.mas_offset(10);
        make.top.mas_offset(75);
        make.width.and.height.mas_equalTo(@80);
    }];
    //名字label
    UILabel * nameLabel = [[UILabel alloc] init];

    nameLabel.text = _dataModel.doctor_name;
    nameLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.mas_equalTo(iconImage.mas_trailing).offset(10);
        make.top.mas_offset(80);
    }];
    //职位Label
    UILabel * jobLabel = [UILabel new];
    jobLabel.text = _dataModel.doctor_title_name;
    jobLabel.textColor = [UIColor grayColor];
    jobLabel.font = [UIFont systemFontOfSize:17];
    [self.view addSubview:jobLabel];
    
    [jobLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(nameLabel.mas_trailing).offset(10);
        make.top.offset(80);
    }];
    //医院名字
    UILabel * hospitalLabel = [UILabel new];
    hospitalLabel.text = _dataModel.doctor_hospital_name;
    hospitalLabel.textColor = [UIColor grayColor];
    [self.view addSubview:hospitalLabel];
    
    [hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(nameLabel.mas_leading);
        make.top.mas_equalTo(nameLabel.mas_bottom).offset(20);
    }];
    //添加button
    UIButton * addButton = [UIButton new];
    [addButton setImage:[UIImage imageNamed:@"yuyueliang.png"] forState:UIControlStateNormal];
    [addButton setTitle:@"  111" forState:UIControlStateNormal];
    [addButton setTitleColor:[UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1] forState:UIControlStateNormal];
    addButton.userInteractionEnabled = NO;
    [self.view addSubview:addButton];
    
    [addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(45);
        make.top.mas_equalTo(iconImage.mas_bottom).offset(20);
    }];
    
//    NSLog(@"%f",addButton.bounds.size.height);
    //小花button
    UIButton * flowerButton = [UIButton new];
    [flowerButton setImage:[UIImage imageNamed:@"xianhua.png"] forState:UIControlStateNormal];
    [flowerButton setTitle:@"  222" forState:UIControlStateNormal];
    [flowerButton setTitleColor:[UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1] forState:UIControlStateNormal];
    flowerButton.userInteractionEnabled = NO;
    [self.view addSubview:flowerButton];

    [flowerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(iconImage.mas_bottom).offset(20);
    }];
    //星旗button
    UIButton * starButton = [UIButton new];
    [starButton setImage:[UIImage imageNamed:@"jinqi.png"] forState:UIControlStateNormal];
    [starButton setTitle:@"  333" forState:UIControlStateNormal];
    [starButton setTitleColor:[UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1] forState:UIControlStateNormal];
    starButton.userInteractionEnabled = NO;
    [self.view addSubview:starButton];
    
    [starButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.offset(-45);
        make.top.mas_equalTo(iconImage.mas_bottom).offset(20);
    }];
    //灰线
    self.lineView = [UIView new];
    self.lineView.backgroundColor = [UIColor colorWithRed:230 / 255.0 green:231 / 255.0 blue:233 / 255.0 alpha:1];
    [self.view addSubview:self.lineView];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.offset(0);
        make.top.mas_equalTo(addButton.mas_bottom).offset(12);
        make.height.mas_equalTo(4);
    }];
}

- (void)setupBottomView{
    
    self.bottomBtn = [UIButton new];
    [self.bottomBtn setBackgroundColor:[UIColor colorWithRed:50 / 255.0 green:196 / 255.0 blue:206 / 255.0 alpha:1]];
    [self.bottomBtn setTitle:@"咨询医生" forState:UIControlStateNormal];
    [self.view addSubview:self.bottomBtn];
    
    [self.bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(5);
        make.trailing.offset(-5);
        make.bottom.offset(-10);
        make.height.mas_equalTo(40);
    }];
//    [self buttonIsSelect];
    
}

#pragma mark - button的点击方法
- (void)didCondictionClick:(UIButton *)condictionBtn{
    
    self.conditionButton.selected = YES;
    self.doctorInfoButton.selected = NO;
    if (self.conditionButton.isSelected) {
        
        [UIView animateWithDuration:0.5 animations:^{
            self.scrollerView.transform = CGAffineTransformMakeTranslation(0, 0);
        }];
    }
//    [self buttonIsSelect];
    
    
    [self.tatalView.bigView setContentOffset:CGPointMake(0, 0) animated:YES];
   
   
}


- (void)didDoctorInfoClick:(UIButton *)doctorInfoBtn{
    
    self.conditionButton.selected = NO;
    self.doctorInfoButton.selected = YES;
   
    
    [self.tatalView.bigView setContentOffset:CGPointMake(SCREEN_WIDTH, 0) animated:YES];
    
    if (self.doctorInfoButton.isSelected) {
        [UIView animateWithDuration:0.5 animations:^{
            self.scrollerView.transform = CGAffineTransformMakeTranslation(SCREEN_WIDTH - 200, 0);
        }];
    }
    
    
}

@end
